import random
from threading import Thread
import time
from common.utility import Utility

# 主函数
def main(thread_count: int = 5):
    Utility.print_info('entered.')
    threads: list[Thread] = []
    for i in range(thread_count):
        threads.append(start_thread())
    for thread in threads:
        thread.join()
    Utility.print_info('exited.')

# 创建线程
def start_thread() -> Thread:
    sleep_time: int = int(random.random()*10)
    thread: Thread = Thread(target=task, args=(sleep_time,))
    thread.start()
    return thread

# 任务
def task(sleep_time: int) -> None:
    Utility.print_info(f'entered. It will sleep {sleep_time} seconds.')
    time.sleep(sleep_time)
    Utility.print_info('exited.')

main()
